package com.zmj.framework.dao.jdbc;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.zmj.framework.bean.Sysuser;
import com.zmj.framework.dao.SysuserDao;
import com.zmj.framework.util.Encryption;
@Repository
public class SysuserDaoJdbc implements SysuserDao {
	@Autowired
	FrmJdbcTemplate jdbcTemplate;

	public Sysuser getSysuser(String yhdh) throws DataAccessException {
		List sysuserList = this.jdbcTemplate.queryForList("select * from frm_sysuser where yhdh='" + yhdh + "'",
				Sysuser.class);

		if ((sysuserList == null) || (sysuserList.size() == 0)) {
			return null;
		}
		return ((Sysuser) sysuserList.get(0));
	}

	private String[] splitString(String str, String split) {
		String tmpStr = str.trim();
		String[] result;
		if (tmpStr.equals(""))
			result = null;
		else {
			result = tmpStr.split(split);
		}
		return result;
	}

	public int validateSysuser(Sysuser sysuser, String strRemoteAddr) throws Exception {
		Sysuser user=getSysuser(sysuser.getYhdh());
		if(user==null){
			return -1;
		}
		List sysuserList = this.jdbcTemplate.queryForList("select * from frm_sysuser where yhdh='" + sysuser.getYhdh() + "' and mm='"+Encryption.md5(sysuser.getYhdh()+sysuser.getMm())+"'",Sysuser.class);
		if ((sysuserList == null) || (sysuserList.size() == 0)) {
			return 0;
		}else{
			return 1;
		}
	}

}